<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Series</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Le styles -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/bootstrap-responsive.css" rel="stylesheet">
    <link href="js/bootstrap.js" rel="stylesheet">

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
</head>
<body>
    <fieldset>
    <legend>瓷砖系列管理
  <a data-toggle="modal" href="#myModal" class="btn btn-warning btn-large">添加新系列</a>
</legend>
</br>
        <div class="span10 columns align-center">
          <div id="myCarousel" class="carousel slide">
            <div class="carousel-inner" >
<?php
include("/usr/local/apache2/htdocs/jibaiwang/lib/Series.php");
include("/usr/local/apache2/htdocs/jibaiwang/lib/ImgStorage.php");
include('log4php/Logger.php');
$cfgfile = "/usr/local/apache2/htdocs/jibaiwang/admin/bootstrap/conf/config.ini";
$defarray = parse_ini_file($cfgfile, 1);
$qlogtag = $defarray["Series"]['qlogtag'];
Logger::configure($defarray["Series"]['qlogcfg']);
$logger = Logger::getLogger($qlogtag);
$host = $defarray["Series"]["host"];
$user = $defarray["Series"]["user"];
$pass = $defarray["Series"]["pass"];
$db = $defarray["Series"]["db"];
$dbh = new Sqlexecutor($host, $user, $pass, $db);
$s = new Series($dbh,$logger);
$a = new ImgStorage();
$str = "";
$list = $s->getList();
if($_REQUEST["op"] == "del")
{
    $res = $s->deleteSeriesByID($_REQUEST["rule_id"]);
    header('Location:Series.php');
}
foreach($list as $key => $value)
{
    $id = $value["id"];
    $img = $value["img"];
    $name = $value["name"];
    if($key == 0)
        $n_class = "item active";
    else
        $n_class = "item";

    $str .= '
    <div class="'.$n_class.' span12">
    <a onclick="modify_del('.$id.')" style="margin-top:0px; margin-right:700px; margin-left:0px; margin-bottom:0px;" class="btn btn-danger span1" >删除</a>
    <li class="span5">
    <a href="http://www.hongdouxiong.com/jibaiwang/admin/bootstrap/TileDiagram.php?tile_series='.$id.'" class="thumbnail span7">
        <img src="http://www.hongdouxiong.com/jibaiwang/'.$img.'" alt="">
        </a> 
        </li> 
        <div class="carousel-caption">
        <p>
        '.$name.' 
        </p>
        </div>
    </div>
        ';
} 
echo $str;
?>
            </div>
            <a class="left carousel-control" href="#myCarousel" data-slide="prev">&lsaquo;</a>
            <a class="right carousel-control" href="#myCarousel" data-slide="next">&rsaquo;</a>
          </div>
    </div>
  <div id="myModal" class="modal hide fade">

<div class="modal-header">
  <a class="close" data-dismiss="modal" >&times;</a>
  <h3>新建新系列</h3>
  </div>

  <form method="post" enctype="multipart/form-data" class="form-horizontal">

  <div class="control-group">
  <label class="control-label" for="seriesname">系列名</label>
  <div class="controls">
  <input type="text" id="seriesname" name="seriesname" class="span3" placeholder="春光无限">
  </div>
  </div>

  <div class="control-group">
  <label class="control-label" for="series_img">上传图片</label>
  <div class="controls">
  <input class="input-file" name="series_img" id="series_img" type="file">
  </div>
  </div>

  <button type="submit" name="submit" class="btn btn-warning btn-large" style="right:500px margin-top:10px; margin-left:50px; margin-left:10px; margin-bottom:10px;" value="1">提交</button>

  </form>
  </div>
<?php
$submit = $_REQUEST["submit"];
$seriesname = $_REQUEST["seriesname"];
if($submit != "")
{

    if ((($_FILES["series_img"]["type"] == "image/gif")
        || ($_FILES["series_img"]["type"] == "image/jgp")
        || ($_FILES["series_img"]["type"] == "image/png")
        || ($_FILES["series_img"]["type"] == "image/jpeg")
        || ($_FILES["series_img"]["type"] == "image/pjpeg"))
        && ($_FILES["series_img"]["size"] < 2000000))
    {
        if ($_FILES["series_img"]["error"] > 0)
        {
            echo "Return Code: " . $_FILES["series_img"]["error"] . "<br />";
        }
        $buffer = file_get_contents($_FILES["series_img"]["tmp_name"]); 
        $ext = explode("/",$_FILES["series_img"]["type"]);
        $img_url = $a->store($buffer, $ext[1]);
        $res = $s->createSeries($seriesname, $img_url);
    }
    else
    {
        $alert =
              '<Script Language="JavaScript">
                  alert("老板，文件过大或该文件不是图片，请重试。");
              </Script>';
              echo $alert;
              exit;
    }
    header('Location:Series.php');
}
?>
    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster
    <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> -->
    <script src="js/jquery.js"></script>
    <script src="js/google-code-prettify/prettify.js"></script>
    <script src="js/bootstrap-transition.js"></script>
    <script src="js/bootstrap-alert.js"></script>
    <script src="js/bootstrap-modal.js"></script>
    <script src="js/bootstrap-dropdown.js"></script>
    <script src="js/bootstrap-scrollspy.js"></script>
    <script src="js/bootstrap-tab.js"></script>
    <script src="js/bootstrap-tooltip.js"></script>
    <script src="js/bootstrap-popover.js"></script>
    <script src="js/bootstrap-button.js"></script>
    <script src="js/bootstrap-collapse.js"></script>
    <script src="js/bootstrap-carousel.js"></script>
    <script src="js/bootstrap-typeahead.js"></script>
    <script src="js/application.js"></script>
    <script src="js/customize.js"></script>

<script>
$('.carousel').carousel({
    interval:10000000000 
})
</script>

<script>
function modify_del(id){
                  if(window.confirm("确定删除吗？")){
                      str="?op=del&rule_id="+id
                        window.open(str,'_self');
                  }
        }
</script>


</body>
</html>
